home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1999 Spring / macformat-077.iso / Shareware Plus / Development / Akua Sweets 131 / Akua Sweets Examples / Resource / Extract Picture Resources < prev    next >
Encoding:
Text File  |  1999-03-04  |  1.5 KB  |  60 lines  |  [TEXT/ToyS]

  1. property kasResType : "PICT" -- Picture resources
  2. property kasOutType : "PICT" -- Picture file type
  3. property kasOutApp : "ttxt" -- Creator for output file
  4. property kasHeader : 512 -- Bytes header in output file
  5.  
  6. on run
  7.     choose file with prompt "Choose a file to extract pictures from…"
  8.     open {the result}
  9. end run
  10.  
  11.  
  12. on open fsObjs
  13.     repeat with fsObj in fsObjs
  14.         DoFile(fsObj)
  15.     end repeat
  16. end open
  17.  
  18.  
  19. on DoFile(fsObj)
  20.     set fname to catalog name of (basic info for fsObj)
  21.     set dstFold to a new folder in fsObj named (fname & " " & kasResType & "s")
  22.     set rsrcs to (the number of resources in fsObj of type kasResType with their info)
  23.     
  24.     set n to the number of items in rsrcs
  25.     set pg to display progress titled fname maximum n
  26.     
  27.     -- {{rName, rNum, rFlags}, {...}}
  28.     repeat with r in rsrcs
  29.         -- Get resource
  30.         set gotOne to true
  31.         try
  32.             set rsrc to the resource in fsObj of type kasResType ¬
  33.                 numbered (item 2 of r)
  34.         on error
  35.             display progress pg labeled ("Error reading: " & (item 2 of r))
  36.             set gotOne to false
  37.         end try
  38.         
  39.         if (gotOne) then
  40.             -- Name?
  41.             copy item 1 of r to rName
  42.             if (rName is "") then set rName to "#" & (item 2 of r)
  43.             
  44.             -- Update progress        
  45.             display progress pg value 0 subtitled rName
  46.             
  47.             -- Create file
  48.             set outFile to a new file in dstFold named rName ¬
  49.                 of type kasOutType with creator kasOutApp
  50.             
  51.             -- Write data
  52.             write data to the data fork of outFile from buffer rsrc at offset kasHeader
  53.         end if
  54.     end repeat
  55.     
  56.     display progress pg with disposal
  57. end DoFile
  58.  
  59.  
  60.